package com.example.eeuse.elasticsearch.controller;


import com.example.eeuse.elasticsearch.mapper.HuaWeiMapper;

import com.example.eeuse.elasticsearch.service.JsonToEsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.log4j.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 测试使用Easy-ES
 * <p>
 * Copyright © 2021 xpc1024 All Rights Reserved
 **/
@Slf4j
@RestController

@RequiredArgsConstructor(onConstructor = @__({@Autowired}))
public class HuaWeiController {
    private static final Logger logger = Logger.getLogger(HuaWeiController.class);
    private final HuaWeiMapper huaweiMapper;
    private final JsonToEsService jsonToEsService;




    /**
     * 读取json文件批量写入easy-es
     *
     *
     * */


    @GetMapping("/importHuaWeiJsonToEsds")
    public String importHuaWeiJsonToEsds() {
//        String jsonFilePath = "/gpadmin/downloads/data.json";
        String jsonFilePath = "/Users/www.macpe.cn/Downloads/data.json";
//        jsonToEsService.readJSON(jsonFilePath);

        jsonToEsService.readJSON(jsonFilePath);
        return "JSON data imported to Elasticsearch.";
    }



    /**
     *
     * 读取excel文件然后写入es
     *
     *
     * */


    @GetMapping("/importHuaWeiExcelToEsd")
    public String importHuaWeiExcelToEsd(@RequestParam("excelFilePath") String excelFilePath) {

//        String excelFilePath = "/Users/www.macpe.cn/Desktop/datas2.xlsx";

        jsonToEsService.importHuaWeiDataFromExcel(excelFilePath);
        return "excel data imported to Elasticsearch.";
    }





























}
